<template>
    <div>
        <el-page-header @back="goBack" content="查看盘点单"></el-page-header>
        <div class="common_line"></div>
        <el-form ref="addForm" :model="addForm" label-width="auto" style="margin-top: 20px;">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="开单时间:" prop="orders_date">
                        <div>{{ addForm.orders_date }}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="经办人:">
                        <div>{{ handler_name }}</div>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="盈亏商品:">
                        <el-table :data="addForm.orders_goods_detail" border style="width: 100%">
                            <el-table-column label="序号" align="center" width="60" prop="index" />
                            <el-table-column label="图片" align="center" width="80">
                                <template slot-scope="scope">
                                    <img v-if="scope.row.imgUrl" :src="scope.row.imgUrl" style="width: 55px;height: 55px;" alt="">
                                </template>
                            </el-table-column>
                            <el-table-column label="商品名称" min-width="100" align="center" prop="prod_name" /> 
                            <el-table-column label="商品编号" align="center" prop="goods_no" />
                            <el-table-column label="库存数" min-width="80" align="center" prop="account_num" />
                            <el-table-column label="实际数" align="center" prop="actual_num" />
                            <el-table-column label="单价(元)" align="center" prop="unit_price_name" />
                            <el-table-column label="盈亏数" align="center" prop="change_num" />
                            <el-table-column label="盈亏额" align="center" prop="total_price_name" />
                        </el-table>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="盈亏总数:">
                        <div>{{ addForm.change_num }}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="盈亏金额:">
                        <div>{{ '￥'+addForm.orders_fee }}</div>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label="备注:">
                        <div>{{ addForm.remark }}</div>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
import { getStocktakingInfo } from '@/api/product';

export default {
    name: 'queryStockTaking',
    data() {
        return {
            addForm: {
                corp: '',
                orders_date: '',
                num_type: 1,
                fee_type: 1,
                orders_fee: 0, //盈亏金额
                change_num: 0, //盈亏总数
                remark: '',
                handler_user: '',
                goods: [],
            },
            bussId: '',
            handler_name: '',
        }
    },
    watch: {
        '$route.query.bussId10': {
            immediate: true, // 首次加载时触发
            handler(newId) {
                if (newId) {
                    this.addForm.corp = this.$store.state.corpId
                    this.bussId = newId
                    this.getInfo()
                }
            }
        }
    },
    props: {
        corpId: {
            type: Number
        },
        orderId: {
            type: Number
        }
    },
    mounted() {
        if (this.orderId){
            this.addForm.corp = this.corpId
            this.bussId = this.orderId
            this.getInfo()
        }
    },
    methods: {
        goBack() {
            this.$emit('hidden', '')
        },
        getInfo() {
            getStocktakingInfo(this.bussId, {corp: this.addForm.corp}).then(res => {
                this.addForm = res.data.data
                this.addForm.orders_goods_detail.forEach((item, index) => {
                    item.index = index+1
                    item.prod_name = item.goods_details.name
                    item.goods_no = item.goods_details.goods_no
                    item.imgUrl = item.goods_details.image?item.goods_details.image.url:'https://anhuiyaoying.com/icon/default.png'
                    this.handler_name = this.addForm.handler_user_detail?this.addForm.handler_user_detail.username:''
                    item.unit_price_name = '￥'+item.unit_price
                    item.total_price_name = '￥'+item.total_price
                })
            })
        }
    }
}
</script>

<style lang="less" scoped>
    @import '../../../style/mixin.less';
    
    .inner_input {
        width: 100px;
        padding: 8px 5px;
    }
</style>